<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.4"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>miniFOC: algorithm/encoder.h File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="Acme_LOGO.png"/></td>
  <td id="projectalign">
   <div id="projectname">miniFOC<span id="projectnumber">&#160;1.0.3</span>
   </div>
   <div id="projectbrief">This open-source project aims to accomplish a FOC(Field Oriented Control) scheme that is operatable with minimum costs in China.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_99d3723365464dd656f512988bb8dbbd.html">algorithm</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a> &#124;
<a href="#var-members">Variables</a>  </div>
  <div class="headertitle"><div class="title">encoder.h File Reference</div></div>
</div><!--header-->
<div class="contents">

<p>this is the header file of <a class="el" href="encoder_8c.html" title="this file contains the code implementation of angle acquisition and initialization functions of sc602...">encoder.c</a>.  
<a href="#details">More...</a></p>

<p><a href="encoder_8h_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ad28e37c20d065e5014ea3a5f2de91e82"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="encoder_8h.html#ad28e37c20d065e5014ea3a5f2de91e82">encoder_zeroing</a> (void)</td></tr>
<tr class="memdesc:ad28e37c20d065e5014ea3a5f2de91e82"><td class="mdescLeft">&#160;</td><td class="mdescRight">correct the mechanical angle zero deviation between the magnetic encoder and FOC.  <a href="encoder_8h.html#ad28e37c20d065e5014ea3a5f2de91e82">More...</a><br /></td></tr>
<tr class="separator:ad28e37c20d065e5014ea3a5f2de91e82"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a28beb7b571ff9e6d39118c8d1324e154"><td class="memItemLeft" align="right" valign="top">unsigned short&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="encoder_8h.html#a28beb7b571ff9e6d39118c8d1324e154">encoder_get_mechanical_angle</a> (void)</td></tr>
<tr class="memdesc:a28beb7b571ff9e6d39118c8d1324e154"><td class="mdescLeft">&#160;</td><td class="mdescRight">read mechanical angle directly from encoder  <a href="encoder_8h.html#a28beb7b571ff9e6d39118c8d1324e154">More...</a><br /></td></tr>
<tr class="separator:a28beb7b571ff9e6d39118c8d1324e154"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a8fbcb19c2f15c20c1a862e0cf64f6771"><td class="memItemLeft" align="right" valign="top">float&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="encoder_8h.html#a8fbcb19c2f15c20c1a862e0cf64f6771">encoder_get_electronic_angle</a> (void)</td></tr>
<tr class="memdesc:a8fbcb19c2f15c20c1a862e0cf64f6771"><td class="mdescLeft">&#160;</td><td class="mdescRight">according to the electrical angle calculated from the mechanical angle, this function will call <a class="el" href="encoder_8c.html#a28beb7b571ff9e6d39118c8d1324e154" title="read mechanical angle directly from encoder">encoder_get_mechanical_angle()</a> function.  <a href="encoder_8h.html#a8fbcb19c2f15c20c1a862e0cf64f6771">More...</a><br /></td></tr>
<tr class="separator:a8fbcb19c2f15c20c1a862e0cf64f6771"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a82c51d78a1f7bb4a5976974ab8d7ffe5"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="encoder_8h.html#a82c51d78a1f7bb4a5976974ab8d7ffe5">encoder_update_speed</a> (void)</td></tr>
<tr class="memdesc:a82c51d78a1f7bb4a5976974ab8d7ffe5"><td class="mdescLeft">&#160;</td><td class="mdescRight">called every 2 milliseconds to calculate the speed.  <a href="encoder_8h.html#a82c51d78a1f7bb4a5976974ab8d7ffe5">More...</a><br /></td></tr>
<tr class="separator:a82c51d78a1f7bb4a5976974ab8d7ffe5"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="var-members" name="var-members"></a>
Variables</h2></td></tr>
<tr class="memitem:a562eacc7259f25574b1ab8ce9d7c6a3e"><td class="memItemLeft" align="right" valign="top">volatile unsigned short&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="encoder_8h.html#a562eacc7259f25574b1ab8ce9d7c6a3e">machine_angle_offset</a></td></tr>
<tr class="memdesc:a562eacc7259f25574b1ab8ce9d7c6a3e"><td class="mdescLeft">&#160;</td><td class="mdescRight">mechanical angle offset, which is used to align the mechanical angle with the zero point of the electrical angle.  <a href="encoder_8h.html#a562eacc7259f25574b1ab8ce9d7c6a3e">More...</a><br /></td></tr>
<tr class="separator:a562eacc7259f25574b1ab8ce9d7c6a3e"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p >this is the header file of <a class="el" href="encoder_8c.html" title="this file contains the code implementation of angle acquisition and initialization functions of sc602...">encoder.c</a>. </p>
<dl class="section author"><dt>Author</dt><dd>Lao·Zhu </dd></dl>
<dl class="section version"><dt>Version</dt><dd>V1.0.1 </dd></dl>
<dl class="section date"><dt>Date</dt><dd>10. October 2021 </dd></dl>

<p class="definition">Definition in file <a class="el" href="encoder_8h_source.html">encoder.h</a>.</p>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a8fbcb19c2f15c20c1a862e0cf64f6771" name="a8fbcb19c2f15c20c1a862e0cf64f6771"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a8fbcb19c2f15c20c1a862e0cf64f6771">&#9670;&nbsp;</a></span>encoder_get_electronic_angle()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">float encoder_get_electronic_angle </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>according to the electrical angle calculated from the mechanical angle, this function will call <a class="el" href="encoder_8c.html#a28beb7b571ff9e6d39118c8d1324e154" title="read mechanical angle directly from encoder">encoder_get_mechanical_angle()</a> function. </p>
<dl class="retval"><dt>Return values</dt><dd>
  <table class="retval">
    <tr><td class="paramname">register</td><td>raw data reading back </td></tr>
  </table>
  </dd>
</dl>

<p class="definition">Definition at line <a class="el" href="encoder_8c_source.html#l00093">93</a> of file <a class="el" href="encoder_8c_source.html">encoder.c</a>.</p>

<p class="reference">References <a class="el" href="foc_8h_source.html#l00026">ELECANGLE_COEFFICIENT</a>, <a class="el" href="encoder_8c_source.html#l00076">encoder_get_mechanical_angle()</a>, <a class="el" href="config_8h_source.html#l00017">ENCODER_RESO</a>, <a class="el" href="foc_8c_source.html#l00020">FOC_Struct</a>, <a class="el" href="foc_8h_source.html#l00024">MECHANGLE_COEFFICIENT</a>, <a class="el" href="foc_8h_source.html#l00018">FOC_Structure_t::mechanical_angle</a>, and <a class="el" href="config_8h_source.html#l00015">POLAR_PAIRS</a>.</p>

<p class="reference">Referenced by <a class="el" href="gd32f1x0__it_8c_source.html#l00104">TIMER2_IRQHandler()</a>.</p>

</div>
</div>
<a id="a28beb7b571ff9e6d39118c8d1324e154" name="a28beb7b571ff9e6d39118c8d1324e154"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a28beb7b571ff9e6d39118c8d1324e154">&#9670;&nbsp;</a></span>encoder_get_mechanical_angle()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">unsigned short encoder_get_mechanical_angle </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>read mechanical angle directly from encoder </p>
<dl class="retval"><dt>Return values</dt><dd>
  <table class="retval">
    <tr><td class="paramname">register</td><td>raw data reading back </td></tr>
  </table>
  </dd>
</dl>

<p class="definition">Definition at line <a class="el" href="encoder_8c_source.html#l00076">76</a> of file <a class="el" href="encoder_8c_source.html">encoder.c</a>.</p>

<p class="reference">References <a class="el" href="encoder_8c_source.html#l00056">encoder_read_data()</a>, <a class="el" href="config_8h_source.html#l00017">ENCODER_RESO</a>, <a class="el" href="encoder_8c_source.html#l00029">last_mechanical_angle</a>, <a class="el" href="encoder_8c_source.html#l00023">machine_angle_offset</a>, and <a class="el" href="encoder_8c_source.html#l00034">total_machine_angle</a>.</p>

<p class="reference">Referenced by <a class="el" href="encoder_8c_source.html#l00093">encoder_get_electronic_angle()</a>, and <a class="el" href="foc_8c_source.html#l00033">foc_calibrate_phase()</a>.</p>

</div>
</div>
<a id="a82c51d78a1f7bb4a5976974ab8d7ffe5" name="a82c51d78a1f7bb4a5976974ab8d7ffe5"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a82c51d78a1f7bb4a5976974ab8d7ffe5">&#9670;&nbsp;</a></span>encoder_update_speed()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void encoder_update_speed </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>called every 2 milliseconds to calculate the speed. </p>

<p class="definition">Definition at line <a class="el" href="encoder_8c_source.html#l00106">106</a> of file <a class="el" href="encoder_8c_source.html">encoder.c</a>.</p>

<p class="reference">References <a class="el" href="filter_8c_source.html#l00056">filter_update_value()</a>, <a class="el" href="foc_8c_source.html#l00020">FOC_Struct</a>, <a class="el" href="foc_8h_source.html#l00019">FOC_Structure_t::rotate_speed</a>, <a class="el" href="encoder_8c_source.html#l00039">systick_mechanical_angle_last</a>, <a class="el" href="encoder_8c_source.html#l00034">total_machine_angle</a>, and <a class="el" href="filter_8c_source.html#l00019">velocity_filter</a>.</p>

<p class="reference">Referenced by <a class="el" href="gd32f1x0__it_8c_source.html#l00077">SysTick_Handler()</a>.</p>

</div>
</div>
<a id="ad28e37c20d065e5014ea3a5f2de91e82" name="ad28e37c20d065e5014ea3a5f2de91e82"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ad28e37c20d065e5014ea3a5f2de91e82">&#9670;&nbsp;</a></span>encoder_zeroing()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void encoder_zeroing </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>correct the mechanical angle zero deviation between the magnetic encoder and FOC. </p>

<p class="definition">Definition at line <a class="el" href="encoder_8c_source.html#l00119">119</a> of file <a class="el" href="encoder_8c_source.html">encoder.c</a>.</p>

<p class="reference">References <a class="el" href="config_8h_source.html#l00019">CALI_TORQUE</a>, <a class="el" href="system_8c_source.html#l00030">delayms()</a>, <a class="el" href="encoder_8c_source.html#l00056">encoder_read_data()</a>, <a class="el" href="foc_8c_source.html#l00099">foc_calculate_dutycycle()</a>, <a class="el" href="encoder_8c_source.html#l00023">machine_angle_offset</a>, <a class="el" href="encoder_8c_source.html#l00034">total_machine_angle</a>, and <a class="el" href="timer_8c_source.html#l00020">update_pwm_dutycycle()</a>.</p>

<p class="reference">Referenced by <a class="el" href="main_8c_source.html#l00139">main()</a>.</p>

</div>
</div>
<h2 class="groupheader">Variable Documentation</h2>
<a id="a562eacc7259f25574b1ab8ce9d7c6a3e" name="a562eacc7259f25574b1ab8ce9d7c6a3e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a562eacc7259f25574b1ab8ce9d7c6a3e">&#9670;&nbsp;</a></span>machine_angle_offset</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">volatile unsigned short machine_angle_offset</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">extern</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>mechanical angle offset, which is used to align the mechanical angle with the zero point of the electrical angle. </p>

<p class="definition">Definition at line <a class="el" href="encoder_8c_source.html#l00023">23</a> of file <a class="el" href="encoder_8c_source.html">encoder.c</a>.</p>

<p class="reference">Referenced by <a class="el" href="encoder_8c_source.html#l00076">encoder_get_mechanical_angle()</a>, <a class="el" href="encoder_8c_source.html#l00119">encoder_zeroing()</a>, <a class="el" href="flash_8c_source.html#l00046">flash_read_parameters()</a>, <a class="el" href="flash_8c_source.html#l00026">flash_write_parameters()</a>, and <a class="el" href="report_8c_source.html#l00015">report_local_variable()</a>.</p>

</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4
</small></address>
</body>
</html>
